package com.sugon.controller.spare;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.SparePartOutEntity;
import com.sugon.service.SparePartOutService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 出库记录Controller
 *
 * @author sugon
 * @date 2019-07-12 08:50:23
 */
@Controller
@RequestMapping("sparepartout")
public class SparePartOutController {
    @Autowired
    private SparePartOutService sparePartOutService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        params.put("delFlag",1);
        //查询列表数据
        Query query = new Query(params);

        List<SparePartOutEntity> sparePartOutList = sparePartOutService.queryList(query);
        int total = sparePartOutService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(sparePartOutList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        SparePartOutEntity sparePartOut = sparePartOutService.queryObject(id);

        return R.ok().put("sparePartOut", sparePartOut);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ResponseBody
    public R save(@RequestBody SparePartOutEntity sparePartOut) {
        sparePartOutService.save(sparePartOut);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ResponseBody
    public R update(@RequestBody SparePartOutEntity sparePartOut) {
        sparePartOutService.update(sparePartOut);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        sparePartOutService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<SparePartOutEntity> list = sparePartOutService.queryList(params);

        return R.ok().put("list", list);
    }

    /**
     * 获取条数
     */
    @RequestMapping("/count")
    @ResponseBody
    public R count(@RequestParam Map<String, Object> params) {
        int total = sparePartOutService.queryTotal(params);
        return R.ok().put("total", total);
    }

}
